-
Notifications
You must be signed in to change notification settings - Fork 470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Elligator2 Forward and Reverse Mappings #612
base: main
Are you sure you want to change the base?
Conversation
Thank you! It will take a bit for me to take a look at this (trying to make some paper deadlines). Re the IETF standard, hasn't that officially been standardized now? RFC 9380. Would be good to have test vectors from there. |
I will get those added. I haven't spent much time looking at that RFC yet, so I can try to work in the interface there as well (and get the rest of the tests passing). |
b4ad93f
to
31ca8dd
Compare
I have added the RFC9380 test vectors for the elligator2 implementation, and an interface that should work if someone wanted to use this to implement the The CI checks should also be passing now. |
a972ecf
to
fcee93b
Compare
Any chance of this landing soon? |
fcee93b
to
c69bda8
Compare
I am working on adding some final tests to ensure that the bits of the ellgator2 representatives appear as uniform random. TLDR: The The specific issue that this is testing for can be described as: An instantiation of Elligator is parameterized by what might be called
a “canonical” square root function, one with the property that
`√a^2 = √(−a)^2` for all field elements `a`. That is, we designate just
over half the field elements as “non-negative,” and the image of the
square root function consists of exactly those elements. A convenient
definition of “non-negative” for Curve25519, suggested by its authors,
is the lower half of the field, the elements `{0, 1, …, (q − 1)+/+2}`.
When there are two options for a square root, take the smaller of the two. Any Elligator implementation that does not do this canonicalization of the final square root, and instead maps a given input systematically to either its negative or non-negative root is vulnerable to the following computational distinguisher. [An adversary could] observe a representative, interpret it as a field
element, square it, then take the square root using the same
non-canonical square root algorithm. With representatives produced by
an affected version of [the elligator2 implementation], the output of
the square-then-root operation would always match the input. With
random strings, the output would match only half the time. The solution from the For a more in-depth explanation see:
This should not impact the general interface of the PR, and I am hoping to have the changes finished within the week. |
The latest commit fixes several issues.
I have no other changes planned for this PR without review / input. |
43ecd08
to
2226611
Compare
I have added another refactor to the elligator2 implementation motivated by feedback based on issues encountered with encoded key distinguishability in obfs4. The changes required to fix the distinguisher resulted in two versions of the elligator2 algorithm which are not interchangeable. More information on the issue can be found here, the solution added to the A test variant exists for legacy implementations that do not use least-square-root value of the representative (i.e. kleshni & signal), but it is not exposed by default. For now I have published my fork as its own crate (see curve25519-elligator2), but my intention is to hopefully get this merged here and eventually yank the forked crate. |
Hi, thank you for this! I played around with this and had some notes:
I'll be reviewing the rest of the PR, but I think these should be addressed before merging. Thanks again! |
with agl/ed25519/extra25519, the kleshni C implementation, and rfc9380.
Edwards rfc9380 tests and elligator representative randomness using tweaks.
fix for subgroup based computational distinguisher and updates / simplifications to the elligator2 interface as a result
8d96835
to
15ad0b3
Compare
You are definitely correct about the implementation of the gt function. I was relying on the idea that other implementations were using a reliable compare, but it turns out they fall victim to the exact issue that you describe. Really what they are trying to check is whether the value is negative, but they do so with by subtracting
For the As an aside, is the implementation of |
Hello,
This is an implementation of the Elligator2 forward and reverse mappings --- points to representative values, as well as representative values to points. The specific goal is to make Elligator mapping for x25519 handshakes possible in pure rust.
This implementation is gated behind a feature flag
"elligator2"
in thecurve25519_dalek
crate for point transforms. I have tested this against the test vectors from theKleshni/Elligator-2
C implementation as well as (a fork of) theagl/ed25519/extra25519
golang implementation. These can be seen in the test cases for this PR.I also added a feature flag
"elligator2"
to thex25519_dalek
crate that exposes aPublicRepresentative
type that mirrors thePublicKey
type in order to exchange only Elligator Representatives when performing a diffie-hellman handshake.This implementation of the Elligator2 transforms (to the best of my ability):
agl/ed25519/extra25519
Kleshni/Elligator-2
I have seen a couple issues and PRs dealing with elligator2 mappings and this library, so I apologize if this is muddying the water . This is a feature that I really needed so I have implemented the functionality based on several existing implementations in other languages.
I am also not an expert in crypto implementations and would greatly appreciate any feedback. I hope this is helpful and potentially solid enough to include in the library. 👍
Related to: